<?php

class Evaluator {
  protected $obj;
  function evaluate($exp, $obj) {
    $this->obj = $obj;
    return preg_replace_callback('/\{([^\}\n]+)\}/', array($this,'replace'), $exp);
  }
  function replace($__match__){
    /*$f=fopen("log.txt","a");
    fwrite($f,get_class($this->obj).json_encode($__match__)."\n");
    fclose($f);*/
    return call_user_func(array($this->obj, $__match__[1]));
  }
}

function dump($node){
  if($node instanceof DOMNodeList) {
    foreach($node as $n) {
      var_dump($n->ownerDocument->saveXML($n));
    }
  } elseif($node instanceof DOMNode) {
    var_dump($node->ownerDocument->saveXML($node));
  } else {
    var_dump($node);
  }
}
